'''
Author: 
ironlionwgHH huanghao_bnu@163.com
Date: 2024-05-23 17:11:40
LastEditors: ironlionwgHH huanghao_bnu@163.com
LastEditTime: 2024-05-23 17:32:24
Description: 

Copyright (c) 2024 by ironlionwgHH huanghao_bnu@163.com, All Rights Reserved. 
'''

import os
import numpy as np

AU_km = 149597870.7

class olg_file():
    def __init__(self, olg_file_path: str, olg_file_name: str):
        self.olg_file_path = olg_file_path
        self.olg_file_name = olg_file_name
        self.olg_file_path_name = os.path.join(self.olg_file_path, self.olg_file_name)
        self.object_name = olg_file_name.split("_")[0]
        # 提取信息
        with open(self.olg_file_path_name, "r") as olg_file:
            olg_file_list = olg_file.readlines()
            self.olg_file_list = olg_file_list
            
            
            
    def extrac_corrected_orbit(self):
        for index in range(len(self.olg_file_list)):
            if "Corrected orbital elements" in self.olg_file_list[index]:
                index_corrected_orbit_title = index
        
        position_vector_line = self.olg_file_list[index_corrected_orbit_title+1]
        if not ("Position vector" in position_vector_line):
            raise ValueError("There is no Position vector in file %s"%(os.path.join(self.olg_file_path, self.olg_file_name)))
        else:
            x,y,z = float(position_vector_line[30:50]), float(position_vector_line[51:72]), float(position_vector_line[73:94])
        
        velocity_vector_line = self.olg_file_list[index_corrected_orbit_title+2]
        if not ("Velocity vector" in velocity_vector_line):
            raise ValueError("There is no Velocity vector in file %s"%(os.path.join(self.olg_file_path, self.olg_file_name)))
        else:
            vx,vy,vz = float(velocity_vector_line[30:50]), float(velocity_vector_line[51:72]), float(velocity_vector_line[73:94])
            
        return x,y,z,vx,vy,vz
        
